package com.gz.rocketmq.controller;


import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;

@RestController
public class ProducerController {

    @Resource(name = "producer")
    private DefaultMQProducer producer;

    @GetMapping("/send/msg")
    public String test(@RequestParam(value = "msg") String msg){
        Message message = new Message("springboot","testTag",msg.getBytes(StandardCharsets.UTF_8));
        try {
            SendResult result = producer.send(message);
            return result.toString();
        }catch (Exception e){
            e.printStackTrace();
            return "file";
        }
    }
}
